package o;

import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnShowListener;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
import com.huawei.hmf.annotation.FragmentDefine;
import java.lang.ref.WeakReference;
import java.util.UUID;
import o.cya.a;
import o.cya.b;
import o.cya.d;

@FragmentDefine(alias = "ShortcutConfirm", protocol = cyi.class)
public class cyj extends DialogFragment implements cye {
    private static WeakReference<cyg> ʻ;
    private static String ˎ;
    private TextView ˊ;
    private CheckBox ˋ;
    private cyg ˏ;
    private cyd ॱ;

    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        String uuid = UUID.randomUUID().toString();
        bundle.putString("state.appgallery.shortcutmanager.STATE_KEY_LISTENER", uuid);
        ˋ(uuid, this.ˏ);
    }

    public Dialog onCreateDialog(Bundle bundle) {
        this.ॱ = (cyd) fiw.ˊ(this).ˏ();
        if (bundle != null) {
            this.ˏ = ˋ(bundle.getString("state.appgallery.shortcutmanager.STATE_KEY_LISTENER"));
        }
        return ˋ();
    }

    public void onDismiss(DialogInterface dialogInterface) {
        super.onDismiss(dialogInterface);
        if (this.ˏ != null) {
            this.ˏ.ˎ();
        }
    }

    Dialog ˋ() {
        Builder builder = new Builder(getActivity(), ˊ());
        builder.setPositiveButton(ˎ(), new OnClickListener(this) {
            final /* synthetic */ cyj ॱ;

            {
                this.ॱ = r1;
            }

            public void onClick(DialogInterface dialogInterface, int i) {
                if (this.ॱ.ˏ != null) {
                    this.ॱ.ˏ.ˏ();
                }
            }
        });
        builder.setNegativeButton(ॱ(), new OnClickListener(this) {
            final /* synthetic */ cyj ˊ;

            {
                this.ˊ = r1;
            }

            public void onClick(DialogInterface dialogInterface, int i) {
                this.ˊ.ˎ(dialogInterface);
            }
        });
        Dialog create = builder.create();
        create.setCanceledOnTouchOutside(false);
        String ˋ = cyh.ˋ(this.ॱ.ˏ());
        CharSequence string = getActivity().getString(a.ˎ, new Object[]{ˋ});
        if (this.ॱ.ʽ()) {
            create.setView(ˏ(string));
        } else {
            create.setMessage(string);
            if (!TextUtils.isEmpty(this.ॱ.ˎ())) {
                create.setMessage(this.ॱ.ˎ());
            }
        }
        create.setOnShowListener(new OnShowListener(this) {
            final /* synthetic */ cyj ˋ;

            {
                this.ˋ = r1;
            }

            public void onShow(DialogInterface dialogInterface) {
                if (this.ˋ.ˏ != null) {
                    this.ˋ.ˏ.ˋ();
                }
            }
        });
        return create;
    }

    int ˊ() {
        if (this.ॱ.ˋ() >= 0) {
            return this.ॱ.ˋ();
        }
        return getActivity().getResources().getIdentifier("androidhwext:style/Theme.Emui.Dialog.Alert", null, null);
    }

    String ˎ() {
        String string;
        if (TextUtils.isEmpty(this.ॱ.ʻ())) {
            string = getActivity().getString(a.ˊ);
        } else {
            string = this.ॱ.ʻ();
        }
        if (this.ॱ.ॱ()) {
            return cyh.ˊ(string);
        }
        return string;
    }

    String ॱ() {
        String string;
        if (TextUtils.isEmpty(this.ॱ.ʼ())) {
            string = getActivity().getString(a.ॱ);
        } else {
            string = this.ॱ.ʼ();
        }
        if (this.ॱ.ॱ()) {
            return cyh.ˊ(string);
        }
        return string;
    }

    private View ˏ(String str) {
        View inflate = LayoutInflater.from(getActivity()).inflate(b.ˎ, null);
        this.ˊ = (TextView) inflate.findViewById(d.ˊ);
        this.ˊ.setText(str);
        this.ˋ = (CheckBox) inflate.findViewById(d.ॱ);
        this.ˋ.setText(a.ˏ);
        if (!TextUtils.isEmpty(this.ॱ.ˎ())) {
            this.ˊ.setText(this.ॱ.ˎ());
        }
        if (!TextUtils.isEmpty(this.ॱ.ॱॱ())) {
            this.ˋ.setText(this.ॱ.ॱॱ());
        }
        return inflate;
    }

    void ˎ(DialogInterface dialogInterface) {
        Context activity = getActivity();
        if (this.ˋ != null && this.ˋ.getVisibility() == 0 && this.ˋ.isChecked() && this.ॱ != null) {
            Object ˊ = this.ॱ.ˊ();
            if (!TextUtils.isEmpty(ˊ)) {
                cyl.ˋ(activity).ˎ(ˊ);
            }
        }
        if (this.ˏ != null) {
            this.ˏ.ˊ();
        }
    }

    public void ˋ(cyg o_cyg) {
        this.ˏ = o_cyg;
    }

    private static void ˋ(String str, cyg o_cyg) {
        ˎ = str;
        ʻ = new WeakReference(o_cyg);
    }

    private static cyg ˋ(String str) {
        if (ˎ == null || !ˎ.equals(str) || ʻ == null) {
            return null;
        }
        cyg o_cyg = (cyg) ʻ.get();
        ʻ = null;
        return o_cyg;
    }
}
